<?php

namespace app\admin\controller;

use app\common\service\AuthService;
use think\Controller;

class Auth extends Controller
{

    protected $authService;

    public function __construct(AuthService $authService)
    {
        parent::__construct();
        $this->authService = $authService;
    }

    /**
     * @api {post} api/admin/auth/addStoreAdmin/sid/:sid 【后台】添加管理员
     * @apiVersion 1.0.0
     * @apiName addStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} username 手机号码作为账号
     * @apiParam {Int} password 密码
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/addStoreAdmin/sid/:sid
     *
     */
    /**
     * @api {post} api/admin/auth/addStoreAdmin/sid/:sid 【后台】添加管理员
     * @apiVersion 2.5.0
     * @apiName addStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} username 手机号码作为账号
     * @apiParam {Int} password 密码
     * @apiParam {Int} role_id 角色ID
     * @apiParam {Int} [uid=0] 绑定用户ID
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/addStoreAdmin/sid/:sid
     *
     */
    public function addStoreAdmin($sid)
    {
        $mobile = $this->request->param('username');
        $password = $this->request->param('password');
        $role_id = $this->request->param('role_id');

        $param = [
            'mobile' => $mobile,
            'password' => $password,
            'role_id' => $role_id
        ];
        $rules = [
            'mobile' => ['require','number'],
            'password' => ['require'],
            'role_id' => ['require', 'number', 'gt:0']
        ];
        $msg = [
            'mobile' => [
                'require' => '手机号码不能为空',
                'number' => '手机号码不合法，只能是数字'
            ],
            'password' => [
                'require' => '密码不能为空'.$password
            ],
            'role_id' => [
                'require' => '角色ID必须',
                'number' => '角色ID不合法',
                'gt' => '角色ID错误'
            ]
        ];

        $validate = $this->validate($param, $rules, $msg);
        if (true !== $validate){
            $this->apiResult('',404,$validate);
        }

        $uid = $this->request->has('uid') ? $this->request->param('uid') : 0;
        $res = $this->authService->addStoreAdmin($sid, $mobile, $password, $role_id, $uid);
        if ($res['status'] == 1){
            $this->apiResult('',200,'添加成功');
        } else {
            $this->apiResult('',404,$res['msg']);
        }

    }

    /**
     * @api {post} api/admin/auth/editStoreAdmin/sid/:sid/admin_id/:admin_id 【后台】编辑管理员
     * @apiVersion 1.0.0
     * @apiName editStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} admin_id 管理员的id
     * @apiParam {String} username 手机号码作为账号
     * @apiParam {Int} password 密码
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/editStoreAdmin/sid/:sid/admin_id/:admin_id
     *
     */
    /**
     * @api {post} api/admin/auth/editStoreAdmin/sid/:sid/admin_id/:admin_id 【后台】编辑管理员
     * @apiVersion 2.5.0
     * @apiName editStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} admin_id 管理员的id
     * @apiParam {Int} role_id 角色ID
     * @apiParam {Int} [uid=0] 绑定用户ID
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/editStoreAdmin/sid/:sid/admin_id/:admin_id
     *
     */
    public function editStoreAdmin($sid,$admin_id)
    {
        $role_id = $this->request->post('role_id');

        $param = [
            'admin_id' => $admin_id,
            'role_id' => $role_id
        ];
        $rules = [
            'admin_id' => ['require','number'],
            'role_id' => ['require', 'number', 'gt:0']
        ];
        $msg = [
            'admin_id' => [
                'require' => '管理员ID不能为空',
                'number' => '管理员ID不合法，只能是数字'
            ],
            'role_id' => [
                'require' => '角色ID必须',
                'number' => '角色ID不合法',
                'gt' => '角色ID错误'
            ]
        ];

        $validate = $this->validate($param, $rules, $msg);
        if (true !== $validate){
            $this->apiResult('',404,$validate);
        }

        $uid = $this->request->has('uid') ? $this->request->post('uid') : 0;

        $res = $this->authService->editStoreAdmin($sid, $admin_id, $role_id, $uid);
        if ($res['status'] == 1){
            $this->apiResult('', 200, $res['msg']);
        } else {
            $this->apiResult('', 404, $res['msg']);
        }

    }


    /**
     * @api {post} api/admin/auth/reset_password/sid/:sid/admin_id/:admin_id 【后台】修改管理员密码
     * @apiVersion 2.5.0
     * @apiName resetPassword
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} admin_id 管理员的id
     * @apiParam {String} password 密码
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/reset_password/sid/:sid/admin_id/:admin_id
     *
     */
    public function reset_password($sid, $admin_id)
    {
        $password = $this->request->param('password');
        if(empty($password)){
            $this->apiResult('', 404, '密码不能为空');
        }
        $result = $this->authService->resetPassword($sid, $admin_id, $password);
        if($result['status']){
            $this->apiResult('', 200, $result['msg']);
        } else {
            $this->apiResult('', 404, $result['msg']);
        }
    }


    /**
     * @api {get} api/admin/auth/get_permissions/sid/:sid 【后台】获取管理员权限
     * @apiVersion 2.5.0
     * @apiName getPermissionsByUsername
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} username 管理员帐号
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {json} data.is_admin 是否为超级管理员(1:是;0:否)
     * @apiSuccess (响应  200) {json} data.permissions 权限列表
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/get_permissions/sid/:sid
     *
     */
    public function get_permissions($sid)
    {
        $username = $this->request->param('username');
        if(!$username){
            $this->apiResult('', 404, '帐号不能为空');
        }
        $result = $this->authService->getPermissionsByUsername($sid, $username);
        if($result['status']){
            $this->apiResult($result['data'], 200, $result['msg']);
        } else {
            $this->apiResult('', 404, $result['msg']);
        }
    }


    /**
     * @api {post} api/admin/auth/deleteStoreAdmin/sid/:sid 【后台】删除管理员
     * @apiVersion 1.0.0
     * @apiName deleteStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} admin_id 管理员的id
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/deleteStoreAdmin/sid/:sid
     *
     */
    public function deleteStoreAdmin($sid)
    {
        $admin_id = $this->request->post('admin_id');

        $res = $this->authService->deleteStoreAdmin($sid,$admin_id);
        if ($res['status'] == 1){
            $this->apiResult('',200,'删除成功');
        } else {
            $this->apiResult('',404,$res['msg']);
        }

    }
    /**
     * @api {post} api/admin/auth/listStoreAdmin/sid/:sid 【后台】管理员列表
     * @apiVersion 1.0.0
     * @apiName listStoreAdmin
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {json} data.aid 管理员索引ID
     * @apiSuccess (响应  200) {json} data.status 管理员状态
     * @apiSuccess (响应  200) {json} data.qrcode_bind_status 扫码登录绑定状态(1:已绑定;0:未绑定)
     * @apiSuccess (响应  200) {json} data.role_id 角色ID
     * @apiSuccess (响应  200) {json} data.role_name 角色名称
     * @apiSuccess (响应  200) {json} data.user_id 用户ID
     * @apiSuccess (响应  200) {json} data.user_nickname 用户昵称
     * @apiSuccess (响应  200) {json} data.user_headimgurl 用户头像
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/listStoreAdmin/sid/:sid
     *
     */
    public function listStoreAdmin($sid)
    {
        $res = $this->authService->listStoreAdmin($sid);
        $this->apiResult($res, 200, '获取成功');
    }

    /**
     * @api {post} api/admin/auth/setStoreAdminHide/sid/:sid 【后台】启用或者禁用管理员
     * @apiVersion 1.0.0
     * @apiName setStoreAdminHide
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} admin_id 管理员Id
     * @apiParam {Int} hide 状态
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/setStoreAdminHide/sid/:sid
     *
     */
    public function setStoreAdminHide($sid) {

        $admin_id = $this->request->post('admin_id');
        $hide = $this->request->post('hide');


        $res = $this->authService->setStoreAdminHide($admin_id,$hide);
        if (1 == $res['status']) {
            return $this->apiResult('',200,'设置成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }

    }

    /**
     * @api {post} api/admin/auth/setStoreAdminGroup/sid/:sid 【后台】设置管理员权限组
     * @apiVersion 1.0.0
     * @apiName setStoreAdminGroup
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} admin_id 管理员Id
     * @apiParam {Int} group_id 分组ID
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/setStoreAdminGroup/sid/:sid
     *
     */
    public function setStoreAdminGroup($sid) {

        $admin_id = $this->request->post('admin_id');
        $group_id = $this->request->post('group_id');

        $res = $this->authService->setStoreAdminGroup($sid,$admin_id,$group_id);

        if (1 == $res['status']) {
            return $this->apiResult('',200,'设置成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }



    }
    /**
     * @api {post} api/admin/auth/listStoreGroup/sid/:sid 【后台】角色列表
     * @apiVersion 1.0.0
     * @apiName listStoreGroup
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/listStoreGroup/sid/:sid
     *
     */
    public function listStoreGroup($sid) {
        $res = $this->authService->listStoreGroup($sid);
        if (1 == $res['status']) {
            return $this->apiResult($res['data'],200,'设置成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }
    }

    /**
     * @api {post} api/admin/auth/addStoreGroup/sid/:sid 【后台】角色添加
     * @apiVersion 1.0.0
     * @apiName addStoreGroup
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} title 角色名称
     * @apiParam {String} description 角色简介
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/addStoreGroup/sid/:sid
     *
     */
    public function addStoreGroup($sid) {

        $title = $this->request->post('title');
        $description = $this->request->post('description');

        $param = [
            'title' => $title,
            'description' => $description
        ];
        $rules = [
            'title' => 'require',
            'description' => 'require'
        ];
        $msg = [
            'title' => ['require' => '用户组名不能为空'],
            'description' => ['require' => '描述不能为空']
        ];

        $validate = $this->validate($param, $rules, $msg);
        if (true !== $validate){
            $this->apiResult('',404,$validate);
        }

        $res = $this->authService->addStoreGroup($sid,$title,$description);
        if (1 == $res['status']) {
            $this->apiResult('',200,'添加成功');
        }
        else{
            $this->apiResult('',404,$res['msg']);
        }

    }

    /**
     * @api {post} api/admin/auth/editStoreGroup/sid/:sid 【后台】角色编辑
     * @apiVersion 1.0.0
     * @apiName editStoreGroup
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} group_id 权限的Id
     * @apiParam {String} title 角色名称
     * @apiParam {String} description 角色简介
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/editStoreGroup/sid/:sid
     *
     */
    public function editStoreGroup($sid) {

        $group_id = $this->request->post('group_id');
        $title = $this->request->post('title');
        $description = $this->request->post('description');

        $res = $this->authService->editStoreAdmin($sid,$group_id,$title,$description);
        if (1 == $res['status']) {
            return $this->apiResult($res['data'],200,'操作成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }

    }

    /**
     * @api {post} api/admin/auth/deleteStoreGroup/sid/:sid/group_id/:group_id 【后台】角色删除
     * @apiVersion 1.0.0
     * @apiName deleteStoreGroup
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {Int} group_id 权限Id
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/deleteStoreGroup/sid/:sid/group_id/:group_id
     *
     */
    public function deleteStoreGroup($sid,$group_id) {

        $res = $this->authService->deleteStoreGroup($sid,$group_id);
        if (1 == $res['status']) {
            return $this->apiResult('',200,'操作成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }
    }

    /**
     * @api {post} api/admin/auth/setStoreGroupHide/sid/:sid 【后台】角色状态
     * @apiVersion 1.0.0
     * @apiName setStoreGroupHide
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} id 角色ID
     * @apiParam {Int} hide 角色状态
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/setStoreGroupHide/sid/:sid
     *
     */
    public function setStoreGroupHide($sid) {

        $group_id = $this->request->post('id');
        $hide = $this->request->post('hide');

        $res = $this->authService->setStoreGroupHide($sid,$group_id,$hide);
        if (1 == $res['status']) {
            return $this->apiResult('',200,'设置成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }
    }


    /**
     * @api {post} api/admin/auth/childStoreAccess/sid/:sid/group_id/:group_id 【后台】读取角色权限
     * @apiVersion 1.0.0
     * @apiName childStoreAccess
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} group_id 角色ID
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/childStoreAccess/sid/:sid/group_id/:group_id
     *
     */
    public function childStoreAccess($sid,$group_id) {

        $res = $this->authService->childStoreAccess($sid,$group_id);
        if (1 == $res['status']) {
            return $this->apiResult($res['data'],200,'获取成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }
    }

    /**
     * @api {post} api/admin/auth/saveStoreAccess/sid/:sid/group_id/:group_id 【后台】用户组权限保存
     * @apiVersion 1.0.0
     * @apiName saveStoreAccess
     * @apiGroup Auth
     *
     * @apiParam {Int} sid 店铺Id
     * @apiParam {String} group_id 角色ID
     * @apiParam {Array} rules 权限
     *
     * @apiSuccess (响应  200) {number} code 请求成功状态码
     * @apiSuccess (响应  200) {json} data 返回数据
     * @apiSuccess (响应  200) {string} [msg='""'] 返回消息说明
     * @apiSuccess (响应  200) {number} time 请求接口时间
     * @apiSuccessExample {json} 请求成功样例
     *   HTTP/1.1 200 OK
     *   {
     *     "code": "200",
     *     "data": "xxx",
     *     "msg": "xxx",
     *     "time": "1492768565"
     *   }
     * @apiUse CODE_4xx
     *
     * @apiSampleRequest api/admin/auth/saveStoreAccess/sid/:sid/group_id/:group_id
     *
     */
    public function saveStoreAccess($sid,$group_id)
    {

        $rules = $this->request->post('rules');

        $res = $this->authService->saveStoreAccess($sid,$group_id,$rules);
        if (1 == $res['status']) {
            return $this->apiResult($res['data'],200,'设置成功');
        }
        else{
            return $this->apiResult('',404,$res['msg']);
        }


    }

}
